//
//  YanZhengMaBtn.m
//  NBProduct
//
//  Created by 张铁军 on 16/6/16.
//  Copyright © 2016年 ping. All rights reserved.
//

#import "YanZhengMaBtn.h"

@implementation YanZhengMaBtn
{
    NSTimer *_verifytimer;
    int _time;
}

-(instancetype)initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self initView];
    }
    return self;
}
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        _DaoJiShitime = 60;
        [self initView];
    }
    return self;
}

-(void)initView{
    
    [self setTitle:@"获取" forState:UIControlStateNormal];
    self.layer.cornerRadius = 3 ;
    
    [self addTarget:self action:@selector(faSongYanZhengMaBtn) forControlEvents:UIControlEventTouchUpInside];
    
}

-(void)faSongYanZhengMaBtn{

    [self.delegate sendYanZhengMa];
    
}
-(void)setDaoJiShitime:(int)DaoJiShitime{
    _DaoJiShitime = DaoJiShitime;
    _time = _DaoJiShitime;
}

-(void)daoJiShi{
   
    
    _verifytimer =[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(verifyBtnChange) userInfo:nil repeats:YES];

    // _fasongAgainBtn.backgroundColor = TUBIAOCOLOR;
    [self setTitle:[NSString stringWithFormat:@"%d",_DaoJiShitime] forState:UIControlStateNormal];
    self.enabled = NO;
    
}
-(void)verifyBtnChange{
    if (_time <=_DaoJiShitime &&_time>0) {
        
        [self setTitle:[NSString stringWithFormat:@"%d",_time] forState:UIControlStateNormal];
        [self setBackgroundColor:_againColor];
        
        [self setEnabled:NO];
        _time--;
    }
    else if(_time ==0)
    {
        [self setTitle:@"获取" forState:UIControlStateNormal];
        [self setBackgroundColor:_againColor];
        [self setEnabled:YES];
        _time =_DaoJiShitime;
        [_verifytimer invalidate];
    }
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
